create procedure insert_account
    @account_number varchar(30),--账户号
    @password varchar(100),
    @type varchar(10),
    @customer_phone_number varchar(15),
    @status int out --返回1为正常 返回2为账户号重复
as
declare @isExist int, --不存在为0
@hash_password varchar(100),-- 加密后的密码
@current_money decimal(11,2)-- 账户钱

select @isExist= count(*) from account where account_number=@account_number and customer_phone_number=@customer_phone_number

    if @isExist=0
        begin
            set @hash_password=sys.fn_VarBinToHexStr(HASHBYTES('SHA2_256',@password));--密码加密
            if (@type='支付宝')
                begin
                    set @current_money=100
                    set @status=1
                    insert into account values (@account_number,@hash_password,@current_money,@type,@customer_phone_number)
                    return
                end
            else if (@type='微信')
                begin
                    set @current_money=200
                    set @status=1
                    insert into account values (@account_number,@hash_password,@current_money,@type,@customer_phone_number)
                    return
                end
            else if (@type='银行卡')
                begin
                    set @current_money=1000
                    set @status=1
                    insert into account values (@account_number,@hash_password,@current_money,@type,@customer_phone_number)
                    return
                end
        end

    else
        begin
            set @status=2
            return
        end
go

